<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<link rel="icon" href="favicon.ico" type="image/x-icon"/>
        <title>修改图文信息-微信管理-{$site.BACK_NAME}</title>
        <include file="Public:jscss" />
		<js href="__PUBLIC__/js/admin/json2.js"/>
		<css href="__PUBLIC__/css/wechat.css"/>
    </head>
    <body>
        <div class="wrap">
            <include file="Public:head" />
            <div class="mainBody">
                <include file="Public:left" />
                <div id="Right">
                    <div class="Item hr">
                        <div class="current">修改图文信息</div>
                    </div>
<!--参考微信群发界面-->
<div class="main_bd">
 <div class="media_preview_area">
 <!--单条-->
  <div class="appmsg editing" id="single_editing" {$display1}>
   <volist name="news" id="nw" offset="0" length="1">
   <div id="js_appmsg_preview1" class="appmsg_content">
    <div id="appmsgItem1_1" data-id="1" class="js_appmsg_item has_thumb">
     <h4 class="appmsg_title"><a onclick="return false;" href="javascript:void(0);" target="_blank">{$nw.title}</a></h4>
     <div class="appmsg_info">
      <em class="appmsg_date"></em>
     </div>
     <div class="appmsg_thumb_wrp">
      <img class="js_appmsg_thumb appmsg_thumb" src="{$nw.img}"/>
      <i class="appmsg_thumb default">封面图片</i>
     </div>
     <p class="appmsg_desc"><present name="nw.digest">{$nw.digest}</present></p>
    </div>
   </div>
   </volist>
   <!--添加一条-->
   <a onclick="return false;" class="create_access_primary appmsg_add" id="js_add_appmsg1" href="javascript:void(0);">
    <i class="icon20_common add_gray">增加一条</i>
   </a>
  </div>
  <!--多条-->
  <div class="appmsg multi editing" id="multi_editing" {$display2}>
   <div id="js_appmsg_preview2" class="appmsg_content">
	<volist name="news" id="nw" key="i">
	<if condition="$i eq 1">
	<div id="appmsgItem1" data-id="1" class="js_appmsg_item has_thumb">
     <div class="appmsg_info"><em class="appmsg_date"></em></div>
	 <div class="cover_appmsg_item">
      <h4 class="appmsg_title"><a href="javascript:void(0);" onclick="return false;" target="_blank">{$nw.title}</a></h4>
      <div class="appmsg_thumb_wrp">
       <img class="js_appmsg_thumb appmsg_thumb" src="{$nw.img}"/>
       <i class="appmsg_thumb default">封面图片</i>
      </div>
      <div class="appmsg_edit_mask">
       <a onclick="return false;" class="icon18_common edit_gray js_edit" data-id="1" href="javascript:;">编辑</a>
      </div>
     </div>
    </div>
	<else/>
	<div id="appmsgItem{$i}" data-id="{$i}" class="appmsg_item js_appmsg_item has_thumb">
     <img class="js_appmsg_thumb appmsg_thumb" src="{$nw.img}"/>
     <i class="appmsg_thumb default">缩略图</i>
     <h4 class="appmsg_title"><a onclick="return false;" href="javascript:void(0);" target="_blank">{$nw.title}</a></h4>
     <div class="appmsg_edit_mask">
      <a class="icon18_common edit_gray js_edit" data-id="{$i}" onclick="return false;" href="javascript:void(0);">编辑</a>
      <a class="icon18_common del_gray js_del" data-id="{$i}" onclick="return false;" href="javascript:void(0);">删除</a>
     </div>
    </div>
	</if>
	</volist>
   </div>
   <!--添加一条-->
   <a onclick="return false;" class="create_access_primary appmsg_add" id="js_add_appmsg2" href="javascript:void(0);">
    <i class="icon20_common add_gray">增加一条</i>
   </a>
  </div>
 </div>
 <!--编辑区显示第一条-->
 <volist name="news" id="nw" offset="0" length="1">
 <div class="media_edit_area">
  <div id="js_appmsg_editor">
   <div class="appmsg_editor" style="margin-top: 0px;">
    <div class="inner">
	 <div class="appmsg_edit_item">
	  <input type="hidden" class="frm_input js_editid" id="quickEditId" value="1"/>
	  <label for="" class="frm_label">备注</label>
	  <p class="tips l">（备注一下本图文的用途）</p>
	  <span class="frm_input_box"><input type="text" class="frm_input js_remark" id="quickRemark" value="{$data['remark']}"/></span>
	 </div>
	 <div class="appmsg_edit_item">
	  <label for="" class="frm_label">
	   <strong class="title">标题</strong>
	   <p class="tips l">（必填）</p>
	  </label>
	  <span class="frm_input_box"><input type="text" class="frm_input js_title" id="quickTitle" value="{$nw.title}"/></span>
      <div class="frm_msg fail js_title_error" style="display: none;">标题不能为空且长度不能超过64字</div>
	 </div>
	 <div class="appmsg_edit_item">
	  <label for="" class="frm_label">
	   <strong class="title">作者</strong>
	   <p class="tips l">（选填）</p>
	  </label>
	  <span class="frm_input_box"><input type="text" class="frm_input js_author " id="quickAuthor" value="{:isset($nw['author']) ? $nw['author'] : ''}"/></span>
      <div class="frm_msg fail js_author_error" style="display: none;">作者不能超过8个字</div>
	 </div>
	 <div class="appmsg_edit_item">
	  <label for="" class="frm_label">
	   <strong class="title">封面</strong>
	  </label>
	  <div class="upload_wrap">
	   <div class="upload_box">
        <div class="upload_area">
         <select name="thumb" id="quickThumb">
		  <option value="">--选择一个封面--</option>
		  <volist name="thumb" id="qt" key="t">
		  <option value="{$qt.path}|{$qt['media_id']}" {:is_selected($qt['path'],$nw['img'])}>{$qt.remark}</option>
		  </volist>
		 </select>
	    </div>
       </div>
	  </div>      
      <p class="frm_tips">
       <label for="" class="frm_checkbox_label js_show_cover_pic selected">
        <i class="icon_checkbox"></i>
        <input type="checkbox" value="1" class="frm_checkbox" id="quickShowCover" {:is_checked('1', $nw['show_cover_pic'])}/>
        封面图片显示在正文中 
       </label>
      </p>
      <div class="frm_msg fail js_cover_error" style="display: none;">必须选择一张封面</div>
     </div>
	 <div class="js_desc_area dn appmsg_edit_item" {$display1}>
	  <label for="" class="frm_label">摘要</label>
	  <span class="frm_textarea_box">
	   <textarea class="js_desc frm_textarea" id="quickDesc">
	   <present name="nw.digest">{$nw.digest}</present>
	   </textarea>
	  </span>
      <div class="frm_msg fail js_desc_error" style="display: none;">摘要不能为空且长度不能超过120字</div>
     </div>
	 <div id="js_ueditor" class="appmsg_edit_item content_edit">
      <label for="" class="frm_label">
       <strong class="title">正文</strong>
      </label>
      <div class="frm_msg fail js_content_error" style="display: none;">正文不能为空且长度不能超过20000字</div>
	  <div id="js_editor" class="edui_editor_wrp edui-default">
	   <textarea id="quickContent" class="input" style="height: 680px; width:480px;visibility:hidden;" name="content">{$nw.content}</textarea>
	  </div>
     </div>
     <div class="js_url_area dn appmsg_edit_item">
	  <label for="" class="frm_label">原文链接</label>
	  <span class="frm_input_box">
	   <input type="text" class="js_url frm_input" id="quickUrl" value="{:isset($nw['content_source_url']) ? $nw['content_source_url'] : ''}"/>
	  </span>
      <div class="frm_msg fail js_url_error" style="display: none;">链接不合法</div>
	 </div>   
    </div>
    <i class="arrow arrow_out" style="margin-top: 0px;"></i>
    <i class="arrow arrow_in" style="margin-top: 0px;"></i>
    <div class="mask" style="display: none;">
    </div>
   </div>
  </div>
 </div>
 </volist>
</div>

<!--存储所有数据的地方-->
<div id="form_div" style="display:none;">
 <volist name="news" id="nw" key="i">
 <div id="appmsgData{$i}" class="appmsgData">
  <input type="text" name="thumb_media_id" value="{$nw.img}|{$nw['thumb_media_id']}"/>
  <input type="text" name="author" value="{:isset($nw['author']) ? $nw['author'] : ''}"/>
  <input type="text" name="title" value="{$nw.title}"/>
  <input type="text" name="content_source_url" value="{:isset($nw['content_source_url']) ? $nw['content_source_url'] : ''}"/>
  <textarea name="content">{$nw.content}</textarea>
  <input type="text" name="digest" value="{:isset($nw['digest']) ? $nw['digest'] : ''}"/>
  <input type="text" name="show_cover_pic" value="{:isset($nw['show_cover_pic']) ? $nw['show_cover_pic'] : '0'}"/>
 </div>
 </volist>
</div>
<form action="" method="post" id="opForm">
<input id="id" type="hidden" name="id" value="{$data['id']}"/>
<input id="remark" type="hidden" name="remark" value=""/>
<input id="json" type="hidden" name="json" value="" />
</form>
                    <div class="commonBtnArea" >
                        <button class="btn submit">提交</button>
                    </div>
                </div>
            </div>
        </div>
        <div class="clear"></div>
        <include file="Public:foot" />
        <js href="__PUBLIC__/js/kindeditor/kindeditor.js,__PUBLIC__/js/kindeditor/lang/zh_CN.js,__PUBLIC__/js/kindeditor/editorbuild.js"/>
    </body>
<script type="text/javascript">
$(function(){
	//隐藏全部错误提示
	function init(){
		$(".js_title_error").hide();
		$(".js_desc_error").hide();
		$(".js_cover_error").hide();
		$(".js_content_error").hide();
	}
	//编辑内容改变时
	var onEditorChange = function(cot){
		if(cot > 20000 || cot == 0){
			$(".js_content_error").show();
		}else{
			$(".js_content_error").hide();
		}
	}
	//编辑器对象
	var  editorObj ;
	editorObj = EDbuildByIdMiniWithFun('quickContent', onEditorChange);
	$(".js_content_error").hide();
	//添加一个
	$(".appmsg_add").click(function(){
		init();
		//隐藏摘要
		$(".js_desc_area").hide();
		//隐藏单个
		$("#single_editing").hide();
		//显示多个
		$("#multi_editing").show();
		//附加一个
		var nowl = $(".appmsg_item").last().attr("data-id");
		if (typeof(nowl) == "undefined"){
			nowl = 2;
		}else{
			nowl = parseInt(nowl) + 1;
		}
		//不能多于10个
		if ($(".appmsg_item").length >= 9){
			$.jBox.tip('最多只能10条图文', 'info');
			return false;
		}
		var html = "";
		html += "<div id='appmsgItem" + nowl + "' data-fileid='' data-id='" + nowl + "' class='appmsg_item js_appmsg_item'> ";
		html += "<img class='js_appmsg_thumb appmsg_thumb' src=''/> ";
		html += "<i class='appmsg_thumb default'>缩略图</i> ";
		html += "<h4 class='appmsg_title'><a onclick='return false;' href='javascript:void(0);' target='_blank'>标题" + nowl + "</a></h4> ";
		html += "<div class='appmsg_edit_mask'> ";
		html += "<a class='icon18_common edit_gray js_edit' data-id='" + nowl + "' onclick='return false;' href='javascript:void(0);'>编辑</a> ";
		html += "<a class='icon18_common del_gray js_del' data-id='" + nowl + "' onclick='return false;' href='javascript:void(0);'>删除</a> ";
		html += "</div> ";
		html += "</div> ";
		$("#js_appmsg_preview2").append(html);
		var data = "";
		data += "<div id='appmsgData" + nowl + "' class='appmsgData'> ";
		data += "<input type='text' name='thumb_media_id' value=''/> ";
		data += "<input type='text' name='author' value=''/> ";
		data += "<input type='text' name='title' value='标题" + nowl + "'/> ";
		data += "<input type='text' name='content_source_url' value=''/> ";
		data += "<textarea name='content'></textarea> ";
		data += "<input type='text' name='digest' value=''/> ";
		data += "<input type='text' name='show_cover_pic' value='0'/> ";
		data += "</div>";
		$("#form_div").append(data);
	});
	//进入编辑
	$(".edit_gray").live("click",function(){
		init();
		var before_id = $("#quickEditId").val();
		var nowid = $(this).attr("data-id");
		if(nowid == before_id){
			return false;
		}else{
			//保存先前一个的数据
			$("#appmsgData" + before_id).find("input[name='thumb_media_id']").last().val($("#quickThumb").val());
			$("#appmsgData" + before_id).find("input[name='author']").last().val($("#quickAuthor").val());
			$("#appmsgData" + before_id).find("input[name='title']").last().val($("#quickTitle").val());
			$("#appmsgData" + before_id).find("input[name='content_source_url']").last().val($("#quickUrl").val());
			$("#appmsgData" + before_id).find("textarea[name='content']").last().val(editorObj.html());
			$("#appmsgData" + before_id).find("input[name='digest']").last().val($("#quickDesc").val());
			$("#appmsgData" + before_id).find("input[name='show_cover_pic']").last().val($("#quickShowCover").attr("checked") ? "1" : "0");
			//移动箭头到选中当前
			if(parseInt(nowid) == 1){
				$(".arrow").css({"margin-top": "0px"});
			}else{
				var mt = parseInt($("#appmsgItem" + nowid).prevAll(".appmsg_item").length);
				mt = mt*120 + 200;
				$(".arrow").css({"margin-top": mt + "px"});
			}
			//载入选中当前的数据
			$("#quickEditId").val(nowid);
			$("#quickThumb").val($("#appmsgData" + nowid).find("input[name='thumb_media_id']").last().val());
			$("#quickAuthor").val($("#appmsgData" + nowid).find("input[name='author']").last().val());
			$("#quickTitle").val($("#appmsgData" + nowid).find("input[name='title']").last().val());
			$("#quickUrl").val($("#appmsgData" + nowid).find("input[name='content_source_url']").last().val());
			editorObj.html($("#appmsgData" + nowid).find("textarea[name='content']").last().val());
			$("#quickDesc").val($("#appmsgData" + nowid).find("input[name='digest']").last().val());
			var is_checked = $("#appmsgData" + nowid).find("input[name='show_cover_pic']").last().val();
			if(is_checked == "1"){
				$("#quickShowCover").attr("checked", true);
			}else{
				$("#quickShowCover").attr("checked", false);
			}
		}
	});
	//删除选中
	$(".del_gray").live("click",function(){
		init();
		var nowid = $(this).attr("data-id");
		$("#appmsgData" + nowid).remove();
		$("#appmsgItem" + nowid).remove();
		//如果删除的是当前编辑则选中第一个
		if(nowid == $("#quickEditId").val()){
			$(".arrow").css({"margin-top": "0px"});
			//载入第一个的数据
			$("#quickEditId").val("1");
			$("#quickThumb").val($("#appmsgData1").find("input[name='thumb_media_id']").last().val());
			$("#quickAuthor").val($("#appmsgData1").find("input[name='author']").last().val());
			$("#quickTitle").val($("#appmsgData1").find("input[name='title']").last().val());
			$("#quickUrl").val($("#appmsgData1").find("input[name='content_source_url']").last().val());
			editorObj.html($("#appmsgData1").find("textarea[name='content']").last().val());
			$("#quickDesc").val($("#appmsgData1").find("input[name='digest']").last().val());
			var is_checked = $("#appmsgData1").find("input[name='show_cover_pic']").last().val();
			if(is_checked == "1"){
				$("#quickShowCover").attr("checked", true);
			}else{
				$("#quickShowCover").attr("checked", false);
			}
		}
		//如果只剩下单个时显示单个
		var len = $(".appmsg_item").length;
		if(len == 0){
			//隐藏多个
			$("#multi_editing").hide();
			//显示摘要
			$(".js_desc_area").show();
			//显示单个
			$("#single_editing").show();
		}
		return false;
	});
	//编辑标题
	//标题不能为空且长度不能超过64字
	$("#quickTitle").keyup(function(){
		var edit_id = $("#quickEditId").val();
		$("#appmsgItem" + edit_id).find(".appmsg_title").last().html("<a onclick='return false;' href='javascript:void(0);' target='_blank'>" + $(this).val() + "</a>");
		if(edit_id == "1"){
			$("#appmsgItem1_1").find(".appmsg_title").last().html("<a onclick='return false;' href='javascript:void(0);' target='_blank'>" + $(this).val() + "</a>");
		}
		if($(this).val() == "" || $(this).val().length > 64){
			$(".js_title_error").show();
		}else{
			$(".js_title_error").hide();
		}
	});
	//编辑摘要
	$("#quickDesc").keyup(function(){
		$("#appmsgItem1_1").find(".appmsg_desc").last().html($(this).val());
		if($(this).val().length > 120){
			$(".js_desc_error").show();
		}else{
			$(".js_desc_error").hide();
		}
	});
	//封面选择
	$("#quickThumb").change(function(){
		var edit_id = $("#quickEditId").val();
		var t_arr = $(this).val().split("|");
		var t_len = t_arr.length;
		if(t_len == 2){
			$("#appmsgItem" + edit_id).addClass("has_thumb");
			$("#appmsgItem" + edit_id).find(".js_appmsg_thumb").last().attr("src", t_arr[0]);
			if(edit_id == "1"){
				$("#appmsgItem1_1").addClass("has_thumb");
				$("#appmsgItem1_1").find(".js_appmsg_thumb").last().attr("src", t_arr[0]);
			}
			$(".js_cover_error").hide();
		}else{
			$("#appmsgItem" + edit_id).removeClass("has_thumb");
			if(edit_id == "1"){
				$("#appmsgItem1_1").removeClass("has_thumb");
			}
			$(".js_cover_error").show();
		}
	});
	//保存全部
	$(".submit").click(function(){
		init();
		var haserr = false;
		var errid = 0;
		var errdom;
		//保存当前(即最后一个)
		var before_id = $("#quickEditId").val();
		$("#appmsgData" + before_id).find("input[name='thumb_media_id']").last().val($("#quickThumb").val());
		$("#appmsgData" + before_id).find("input[name='author']").last().val($("#quickAuthor").val());
		$("#appmsgData" + before_id).find("input[name='title']").last().val($("#quickTitle").val());
		$("#appmsgData" + before_id).find("input[name='content_source_url']").last().val($("#quickUrl").val());
		$("#appmsgData" + before_id).find("textarea[name='content']").last().val(editorObj.html());
		$("#appmsgData" + before_id).find("input[name='digest']").last().val($("#quickDesc").val());
		$("#appmsgData" + before_id).find("input[name='show_cover_pic']").last().val($("#quickShowCover").attr("checked") ? "1" : "0");
		//组装所有数据,并检查数据有效性
		var obj = {};
		//当前全部图文
		var arr = new Array();
		$(".appmsgData").each(function(i){
			errid = i+1;
			errdom = $(this);
			var one = {};
			var t_arr = $(this).find("input[name='thumb_media_id']").last().val().split("|");
			var t_len = t_arr.length;
			if(t_len == 2){
				one["thumb_media_id"] = t_arr[1];
			}else{
				haserr = true;
				$(".js_cover_error").show();
			}
			var t_aor = $(this).find("input[name='author']").last().val();
			if(t_aor !== ""){
				if(t_aor.length > 8){
					haserr = true;
					$(".js_author_error").show();
				}
				one["author"] = t_aor;
			}
			var t_ttl = $(this).find("input[name='title']").last().val();
			if(t_ttl == "" || t_ttl.length > 64){
				haserr = true;
				$(".js_title_error").show();
			}
			one["title"] = t_ttl;
			var t_csu = $(this).find("input[name='content_source_url']").last().val();
			if(t_csu !== ""){
				one["content_source_url"] = t_csu;
			}
			var t_ctt = $(this).find("textarea[name='content']").last().val();
			if(t_ctt == "" || t_ctt.length > 20000){
				haserr = true;
				$(".js_content_error").show();
			}
			one["content"] = t_ctt;
			var t_dgt = $(this).find("input[name='digest']").last().val();
			if(t_dgt.length > 120){
				haserr = true;
				$(".js_desc_error").show();
			}else if(t_dgt !== ""){
				one["digest"] = t_dgt;
			}
			one["show_cover_pic"] = $(this).find("input[name='show_cover_pic']").last().val();
			arr.push(one);
			if(haserr){
				return false;
			}
		});
		//出错处理
		if(haserr){			
			//载入出现错误的数据
			$("#quickEditId").val(errdom.attr("id").replace("appmsgData",""));
			$("#quickThumb").val(errdom.find("input[name='thumb_media_id']").last().val());
			$("#quickAuthor").val(errdom.find("input[name='author']").last().val());
			$("#quickTitle").val(errdom.find("input[name='title']").last().val());
			$("#quickUrl").val(errdom.find("input[name='content_source_url']").last().val());
			editorObj.html(errdom.find("textarea[name='content']").last().val());
			$("#quickDesc").val(errdom.find("input[name='digest']").last().val());
			var is_checked = errdom.find("input[name='show_cover_pic']").last().val();
			if(is_checked == "1"){
				$("#quickShowCover").attr("checked", true);
			}else{
				$("#quickShowCover").attr("checked", false);
			}
			if(parseInt(errid) == 1){
				$(".arrow").css({"margin-top": "0px"});
			}else{
				var mt = parseInt(errid)-2;
				mt = mt*120 + 200;
				$(".arrow").css({"margin-top": mt + "px"});
			}
			return false;
		}
		obj["articles"] = arr;
		$("#remark").val($("#quickRemark").val());
		$("#json").val(JSON.stringify(obj));
		//修改提醒
		$.jBox.confirm(
			'确定修改【<b>'+$("#remark").val()+'</b>】?<br/>修改后该资源的Media_id将发生改变。<br/>已发送的原图文在本次修改中不会生效，请注意！',
			"温馨提示",
			function(v, h, f) {
				if (v == true) {
					commonAjaxSubmit("","#opForm");
				}
			},
			{buttons: {'是': true, '否': false}}
		);
	});
	//离开页面的提示
	$(window).bind('beforeunload',function(){return '您输入的内容尚未保存，确定离开此页面吗？';});
});
</script>
</html>